import { Component, OnInit } from '@angular/core';
import { AGENT_BALANCE_TYPE, USER_ROLE_OPTION } from '../../../constant/dictionary';
import { FinancesService } from '@core/routes-services/finances.service';
import { ActivatedRoute } from '@angular/router';
import { MyModalHelper } from '@core/my-modal.helper';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-changeback-list',
  templateUrl: './changeback-list.component.html',
})
export class ChangebackListComponent implements OnInit {


  isLoading = false;
  keyword: any;
  financeType: any;
  type: any = "chargeback";// shopping-购物，recharge-充值 chargeback-扣款
  page: any = { number: 1, size: 10, totalElements: 0, content: [] };
  userRoleOption: any [] = USER_ROLE_OPTION;
  agentBalanceType: any [] = AGENT_BALANCE_TYPE;


  constructor(private message: NzMessageService,
              private route: ActivatedRoute,
              private financesService: FinancesService,
              private modalHelper: MyModalHelper) {
  }

  ngOnInit() {
    this.initPage();
  }

  initPage() {
    this.isLoading = true;
    this.financesService.outPagination(this.page, this.keyword, this.type,this.financeType).then((res) => {
      if (res.status.toString().startsWith('20')) {
        this.page = res.data;
        ++this.page.number;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }

  /**
   * 搜索重置分页数据
   */
  search() {
    this.page = { number: 0, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }

  changePageNo(pageNo) {
    this.page = { number: pageNo, size: 10, totalElements: 0, content: [] };
    this.initPage();
  }

  editEntity = (entity) => {
    this.message.success('todo');
    // let temp: boolean;
    // temp = myValidNull(entity.id);
    // const bak = {};
    // Object.assign(bak, entity);
    // this.modalHelper.open(UserEditComponent, { entity: bak }, 500, {
    //   nzTitle: '用户信息',
    // }).subscribe(result => {
    //   if(result){
    //     temp ? this.search() : this.changePageNo(this.page.number);
    //   }
    // }, (error) => {
    //   console.error('弹窗回调出错：', error);
    // });
  };


}
